import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.TreeMap;
import java.util.TreeSet;

public class TravelJournal extends HtmlAble {

	ArrayList<Picture> Pictures;
	TravelPlans Plans;
	ArrayList<String> Text;
	ArrayList<String> Expenses;

	public ArrayList<Picture> getPictures() {
		return Pictures;
	}


	public void setPictures(ArrayList<Picture> pictures) {
		Pictures = pictures;
	}


	public TravelPlans getPlans() {
		return Plans;
	}


	public void setPlans(TravelPlans plans) {
		Plans = plans;
	}


	public ArrayList<String> getText() {
		return Text;
	}


	public void setText(ArrayList<String> text) {
		Text = text;
	}


	public ArrayList<String> getExpenses() {
		return Expenses;
	}


	public void setExpenses(ArrayList<String> expenses) {
		Expenses = expenses;
	}


	public TravelJournal()
	{
		Pictures = new ArrayList<Picture>();
		Plans = new TravelPlans();
		Text = new ArrayList<String>();
		Expenses = new ArrayList<String>();
	}
	
	public TreeMap<String, TreeSet<Picture>> buildAlbumMap()
	{
		TreeMap<String, TreeSet<Picture>> map = new TreeMap<String,TreeSet<Picture>>();
		for(Picture pic: Pictures)
		{
			for(String album: pic.Album)
			{
				if(!map.containsKey(album))
				{
					map.put(album, new TreeSet<Picture>());
				}
				map.get(album).add(pic);
			}
		}
		return map;
	}
	
	public TreeMap<String, TreeSet<HtmlAble>> buildLocationMap()
	{
		TreeMap<String, TreeSet<HtmlAble>> map = new TreeMap<String,TreeSet<HtmlAble>>();
		for(Picture pic: Pictures)
		{
			if(pic.getLocation() != null)
			{
				if(!map.containsKey(pic.getLocation()))
				{
					map.put(pic.getLocation(), new TreeSet<HtmlAble>());
				}
				map.get(pic.getLocation()).add(pic);
			}
		}
		for(TravelPlansMakeup makeup : Plans.getMakeup() )
		{
			if(makeup.getLocation() != null)
			{
				if(!map.containsKey(makeup.getLocation()))
				{
					map.put(makeup.getLocation(), new TreeSet<HtmlAble>());
				}
				map.get(makeup.getLocation()).add(makeup);
			}
		}
		return map;
	}
	
	public TreeMap<String, TreeSet<HtmlAble>> buildPlaceMap()
	{
		TreeMap<String, TreeSet<HtmlAble>> map = new TreeMap<String,TreeSet<HtmlAble>>();
		for(Picture pic: Pictures)
		{
			if(pic.getPlace() != null)
			{
				if(!map.containsKey(pic.getPlace()))
				{
					map.put(pic.getPlace(), new TreeSet<HtmlAble>());
				}
				map.get(pic.getPlace()).add(pic);
			}
		}
		for(TravelPlansMakeup makeup : Plans.getMakeup() )
		{
			if(makeup.getPlace() != null)
			{
				if(!map.containsKey(makeup.getPlace()))
				{
					map.put(makeup.getPlace(), new TreeSet<HtmlAble>());
				}
				map.get(makeup.getPlace()).add(makeup);
			}
		}
		return map;
	}
	
	public TreeMap<String, TreeSet<HtmlAble>> buildPersonMap()
	{
		TreeMap<String, TreeSet<HtmlAble>> map = new TreeMap<String,TreeSet<HtmlAble>>();
		for(Picture pic: Pictures)
		{	
			for(String person: pic.getPeople())
			{
				if(!map.containsKey(person))
				{
					map.put(person, new TreeSet<HtmlAble>());
				}
				map.get(person).add(pic);
			}
		}
		return map;
	}
	
		
	public TreeMap<Picture.MyDate, TreeSet<HtmlAble>> buildDateMap()
	{
		TreeMap<Picture.MyDate, TreeSet<HtmlAble>> map = new TreeMap<Picture.MyDate,TreeSet<HtmlAble>>();
		for(Picture pic: Pictures)
		{
			if(pic.getDate()!=null)
			{
				if(!map.containsKey(pic.getDate()))
				{
					map.put(pic.getDate(), new TreeSet<HtmlAble>());
				}
				map.get(pic.getDate()).add(pic);
			}
		}
		return map;
	}
		
	public TreeSet<HtmlAble> doSearch(String searchString)
	{
		TreeSet<HtmlAble> list = new TreeSet<HtmlAble>();
		for(Picture pic: Pictures)
		{
			if(pic.getHTML().toLowerCase().contains(searchString.toLowerCase()))
			{
				list.add(pic);
			}
		}
		for(TravelPlansMakeup makeup : Plans.getMakeup() )
		{
			if(makeup.getHTML().toLowerCase().contains(searchString.toLowerCase()))
			{
				list.add(makeup);
			}
		}
		return list;
	}
	
	public String getHTML()
	{
		String rep = "<a href = \"www.google.com\"> google </a>";
		rep += "<h1>Travel Journal: </h1>\n";
		if(Expenses.size() >= 0)
		{
			rep+= "<h2>Expenses:</h2>\n";
			for(String expense: Expenses)
			{
				rep+="<p>"+expense+"</p>\n";
			}
		}
		if (Text.size() >= 0)
		{
			rep+= "<h2>Comments:</h2>\n";
			for(String text: Text)
			{
				rep+="<p>"+text+"</p>\n";
			}
		}
		return rep;
	}	
}
